package edu.sctu.jarime.june.day20150611;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by user19 on 2015/6/11.
 */

/**
 * 认识编码
 */
public class UseEncoding {
    public static void main(String[] args) throws Exception {
        String s = "李莉ABC";
        byte[] bytes = s.getBytes();//使用java中自定义的编码
        for (byte b : bytes) {
            System.out.print(Integer.toHexString(b & 0xff) + "\t");
        }

        System.out.println();
        byte[] bytes1 = s.getBytes("gbk");//将String转化成gbk编码

        //gbk编码中文使用两个字节，英文使用一个字节
        for (byte b : bytes1) {//遍历输出
            System.out.print(Integer.toHexString(b & 0xff) + "\t");
        }


        System.out.println();
        byte[] bytes2 = s.getBytes("utf-8");

        //utf-8编码中文使用三个字节，英文使用一个字节
        for (byte b : bytes2) {
            System.out.print(Integer.toHexString(b & 0xff) + "\t");
        }


        System.out.println();
        String str1 = new String(bytes, "utf-8");
        System.out.println(str1);

    }
}
